/*
 * Amazon Software Tecnologia
 * http://www.amazon-software.net
 */
package tv.dao;

import tv.pojo.Celular;

import javax.management.Query;

import java.util.List;


/**
 * DOCUMENT ME!
 *
 * @author $Author$
 * @version $Revision$
 */
public class CelularDao extends GenericDao<Celular>
{
   /**
    * DOCUMENT ME!
    *
    * @param query
    *
    * @return
    *
    * @exception Exception
    */
   public List busca(String query) throws Exception
   {
      List lista = null;
      session = factory.openSession();
      tx = session.beginTransaction();

      try
      {
         Query queryBusca = (Query) session.createQuery(query);

//            lista = queryBusca.list();
         tx.commit();
      }
      catch (Exception e)
      {
         throw new Exception(e);
      }
      finally
      {
         session.close();
      }

      return lista;
   }

   /**
    * DOCUMENT ME!
    *
    * @param celular
    *
    * @exception Exception
    */
   @Override
   public void save(Celular celular) throws Exception
   {
      try
      {
         session = factory.openSession();
         tx = session.beginTransaction();
         session.save(celular);
         session.flush();
         tx.commit();
      }
      catch (Exception e)
      {
         tx.rollback();
         throw new Exception(e);
      }
      finally
      {
         session.close();
      }
   }

   /**
    * DOCUMENT ME!
    *
    * @param celular
    *
    * @exception Exception
    */
   @Override
   public void update(Celular celular) throws Exception
   {
      try
      {
         session = factory.openSession();
         tx = session.beginTransaction();
         session.update(celular);
         session.flush();
         tx.commit();
      }
      catch (Exception e)
      {
         tx.rollback();
         throw new Exception(e);
      }
      finally
      {
         session.close();
      }
   }
}
